
#ifndef _MEMBER_BGROUP_H_
#define _MEMBER_BGROUP_H_

#include <BNode>
#include <BShape>
#include <BConstraint>
#include <BMaterial>
#include <BPhysics>
#include <BOctTree>
#include <BGroup>

#define group_member(group)		((member_BGroup*)((BGroup*)group)->_ptr)

namespace BWE
{
	class member_BGroup : public BObject
	{
		friend class BGroup;

	public:
		inline void raiseDirty()
		{
			BGroup* group = boss;
			while (group)
			{
				group_member(group)->dirtySpace = true;
				group->emit(Signal_Dirty);
				group = group_member(group)->parent;
			}
		}
		inline void raiseSignal(int signal, const BValue& value = BValue())
		{
			BGroup* group = boss;
			while (group)
			{
				group->emit(signal, value);
				group = group_member(group)->parent;
			}
		}

	public:
		member_BGroup(BGroup* group);
		~member_BGroup();

		void update(BReal time);

		void slotShapeFresh(BObject* object, const BValue& value);
		void slotShapeDirty(BObject* object, const BValue& value);
		void slotShapeFlushed(BObject* object, const BValue& value);
		void slotShapeTransformed(BObject* object, const BValue& value);

		void slotNodeFresh(BObject* object, const BValue& value);
		void slotNodeDirty(BObject* object, const BValue& value);
		void slotNodeFlushed(BObject* object, const BValue& value);
		void slotNodeTransformed(BObject* object, const BValue& value);

		void slotConstraintChanged(BObject* object, const BValue& value);

	public:
		BGroup*					boss;
		BGroup*					parent;
		bool					visible;
		bool					dirtySpace;
		BSpace					space;
		BSet<BShapeHolder>		shapes;
		BSet<BNodeHolder>		nodes;
		BSet<BConstraintHolder>	constraints;
		BArray<BGroupHolder>	children;
	};
}
#endif
